package com.action;

import com.from.Action;
import com.from.ActionFrom;
import com.utils.ActionMapping;
import com.utils.FullBeans;
import com.from.RegisterActionFrom;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * Created by Administrator on 2015/2/3.
 */
@WebServlet(name = "RegisterServlet")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


      /*  String username = request.getParameter("username");
        String password = request.getParameter("password");
        String age = request.getParameter("age");*/
       // String hidd = request.getParameter("hidd");


        ActionFrom registerActionFrom = FullBeans.Full(request.getParameter("hidd"),request);

        System.out.println("|||"+registerActionFrom);

        String message;
        Action action = null;
        String hidd = request.getParameter("hidd");
      /*  if (hidd.equals("com.from.RegisterActionFrom")){


            action = new RegisterAction();
            System.out.println(action);
            message= action.exexute(registerActionFrom);
            PrintWriter printWriter = response.getWriter();
            printWriter.print(message);
            printWriter.flush();
            printWriter.close();
        }*/

        Map<String,String> map = ActionMapping.getMap();

        try
        {
            String actionName = map.get(hidd);
            Class clazz = Class.forName(actionName);
            action =(Action)clazz.newInstance();
            message= action.exexute(registerActionFrom);
            PrintWriter printWriter = response.getWriter();
            printWriter.print(message);
            printWriter.flush();
            printWriter.close();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }
}
